package com.module.material.service;

import com.core.dao.DhConfig;
import com.core.dao.DhDao;
import com.module.material.entity.MaterialVO;

import java.util.ArrayList;
import java.util.List;

public class MaterialService {
    public static List<MaterialVO> query(MaterialVO param, DhConfig dbConfig) throws Exception {
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT");
        sql.append(" t.id                             as id").append(",");
        sql.append(" t.material_no                    as materialNo").append(",");
        sql.append(" t.inner_drawing_no               as innerDrawingNo").append(",");
        sql.append(" t.material_name                  as materialName").append(",");
        sql.append(" t.material_short                 as materialShort").append(",");
        sql.append(" t.material_flag                  as materialFlag").append(",");
        sql.append(" t.material_type                  as materialType").append(",");
        sql.append(" t.material_group_no              as materialGroupNo").append(",");
        sql.append(" t.inner_code                     as innerCode").append(",");
        sql.append(" t.specifications                 as specifications").append(",");
        sql.append(" t.model                          as model").append(",");
        sql.append(" t.unit                           as unit").append(",");
        sql.append(" t.data_source                    as dataSource").append(",");
        sql.append(" t.product_status                 as productStatus").append(",");
        sql.append(" t.tenant_id                      as tenantId");
        sql.append("   FROM md_material t");
        sql.append("  WHERE 1 > 0 ");
        List<Object> paraList = new ArrayList();
        if (param.getId() != null) {
            sql.append("and t.id = ? ");
            paraList.add(param.getId());
        }
        if (param.getTenantId() != null && param.getTenantId().length() > 0) {
            sql.append("and t.tenant_id = ? ");
            paraList.add(param.getTenantId());
        }
        if (param.getMaterialNo() != null && param.getMaterialNo().length() > 0) {
            sql.append("and t.material_no = ? ");
            paraList.add(param.getMaterialNo());
        }
        List<MaterialVO> dataList = DhDao.list(sql.toString(), paraList, MaterialVO.class, dbConfig);
        return dataList;
    }
}
